export default {
  data() {
    return {
      requirement: {
        name: "",
        reason: "",
        beginDate: null,
        endDate: null,
        isUrgent: null,
        post: "",
        salary: "",
        amount: "",
        experience: "",
        education: "",
        type: "",
        postDesc: "",
        address: "",
        responsibility: ""
      },
      requirementEditRules: {
        name: [
          { required: true, trigger: 'blur', message: '请输入标题' }
        ],
        reason: [
          { required: true, trigger: 'blur', message: '请输入申请原因' }
        ],
        beginDate: [
          { 
            required: true, 
            trigger: ['blur', 'change'],
            validator: (rule, value, callback) => {
              if (value == null) {
                callback(new Error('请选择期限开始时间'));
              } else if (this.requirement.endDate == null) {
                callback(new Error('请选择期限结束时间'));
              } else if(new Date(value) > new Date(this.requirement.endDate)) {
                callback(new Error('开始时间不能大于结束时间'));
              } else {
                callback()
              }
            }, 
          }
        ],
        post: [
          { required: true, trigger: 'blur', message: '请输入招聘岗位' }
        ],
        salary: [
          { required: true,  trigger: ['blur', 'change'], message: '请选择岗位薪资' }
        ],
        amount: [
          { 
            required: true, 
            trigger: ['blur', 'change'],
            validator: (rule, value, callback) =>{
              if(!this.regCheck('empty', value)) {
                callback(new Error('请输入招聘人数'))
              } else if(this.regCheck('pInteger', value)){
                callback(new Error('只能输入正整数数字'))
              } else {
                callback()
              }
            }
          }
        ],
        experience: [
          { required: true, trigger: ['blur', 'change'], message: '请选择经验要求' }
        ],
        education: [
          { required: true, trigger: ['blur', 'change'], message: '请选择学历' }
        ],
        type: [
          { required: true, trigger: ['blur', 'change'], message: '请选择工作类型' }
        ],
        postDesc: [
          { 
            required: true, 
            trigger: 'blur',
            validator: (rule, value, callback) => {
              if(!this.regCheck('empty', value)){
                callback(new Error('请输入技能要求'))
              } else {
                callback()
              }
            }, 
          }
        ],
        address: [
          { required: true, trigger: 'blur', message: '请输入工作地点' }
        ],
        responsibility: [ // textarea可输入空格
          { 
            required: true, 
            trigger: 'blur',
            validator: (rule, value, callback) => {
              if(!this.regCheck('empty', value)){
                callback(new Error('请输入工作内容'))
              } else {
                callback()
              }
            }, 
          }
        ]
      }
    }
  },
}